﻿#pragma once

#include <QWidget>
#include "ui_H264OrH265FilePlayWindow.h"
#include <QCloseEvent>
#include <QString>
#include <thread>
#include <chrono>
#include <QDebug>
#include "../../../common/utils/BinaryFileReader.h"

extern "C"
{
#include "libavcodec/avcodec.h"
#include "libavutil/avutil.h"
}

#include "../../sdl/render/IVideoRenderView.h"

/// <summary>
/// H264/H265文件播放器
/// </summary>
class H264OrH265FilePlayWindow : public QWidget
{
	Q_OBJECT

public:
	H264OrH265FilePlayWindow(QWidget* parent = nullptr);
	~H264OrH265FilePlayWindow();
	void Draw();
	void Release();
protected:
	// 重写关闭事件处理函数
	void closeEvent(QCloseEvent* event) override;

public slots:
	void onVideoFormatChanged(int pos);
	void onCodecFormatChanged(int pos);
	void onSelectedFile();
	void onStartPlayVideo();
	
private:
	Ui::H264OrH265FilePlayWindow ui;
	int codecId = 0;
	BinaryFileReader* reader = nullptr;
	IVideoRenderView* renderView = nullptr;
	QString fileName;
	std::unique_ptr<std::thread> renderThread;
	bool isRunning = true;
	unsigned char inbuf[4096] = { 0 };
	int videoWidth = 1920;
	int videoHeight = 1080;
	bool isHwCodec = false;
};
